#
# isp 3a Makefile
#

ifeq ($(COMP_PARAM_FILE), )
    COMP_PARAM_FILE:=../../Makefile.param
    include $(COMP_PARAM_FILE)
endif

CUSTOMER_3A_PATH := $(CUSTOMER_3A_ROOT)
LIB_PATH = $(CUSTOMER_3A_PATH)/lib
OBJ_PATH = ./obj

ISP_INC := -I$(CUSTOMER_3A_PATH)/include\
	-I$(COMM_INC)\

LIB_A := $(LIB_PATH)/libcustomer_af.a
LIB_S := $(LIB_PATH)/libcustomer_af.so

ARFLAGS = rcv
CFLAGS += -Wall -fPIC

ifeq ($(EIGDB),EI_GDB)
CFLAGS += -g
endif

CFLAGS  += -O2
CFLAGS  += $(LIBS_CFLAGS)
DFLAGS  := -DEXT_REG
DFLAGS  += $(MDP_CFLAGS)

DEPEND_FILE := $(foreach file,$(subst -I, ,$(ISP_INC)), $(wildcard $(file)/*.h))
SRCS = $(wildcard ./*.c)
OBJS = $(SRCS:%.c=%.o)
OBJS := $(OBJS:./%=obj/%)

COMPILE = $(CC) $(CFLAGS) $(DFLAGS) $(ISP_INC) -lm

$(OBJ_PATH)/%.o: ./%.c $(DEPEND_FILE)
	@(echo "compiling $< ...")
	@[ -e $(LIB_PATH) ] || mkdir -p $(LIB_PATH)
	@[ -e $(OBJ_PATH) ] || mkdir -p $(OBJ_PATH)
	@($(COMPILE) -o $@ -c $<)

all:$(OBJS)
	@($(AR) $(ARFLAGS) $(LIB_A) $(OBJS))
	@($(CC) $(LIBS_LD_CFLAGS) -shared -fPIC -o $(LIB_S) $(OBJS))
	@mkdir -p $(INS_LIB)
	@cp $(LIB_S) $(INS_LIB)
	@cp $(LIB_A) $(INS_LIB)
clean:
	@$(RM) -rf $(LIB_A) $(LIB_S) $(OBJS)
	@$(RM) -rf $(LIB_PATH) $(OBJ_PATH)

